﻿using System;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Uow;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.MySQL;
using Volo.Abp.FeatureManagement.EntityFrameworkCore;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.Modularity;
using Volo.Abp.OpenIddict.EntityFrameworkCore;
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.TenantManagement.EntityFrameworkCore;

namespace Acme.ConcreteMixDesign.EntityFrameworkCore;

/// <summary>
/// 设置依赖，模块类管理整个模块的生命周期（模块初始化，模块配置，模块销毁，都包含在AbpModule中）
/// </summary>
[DependsOn(
    typeof(ConcreteMixDesignDomainModule),
    typeof(AbpIdentityEntityFrameworkCoreModule),
    typeof(AbpOpenIddictEntityFrameworkCoreModule),
    typeof(AbpPermissionManagementEntityFrameworkCoreModule),
    typeof(AbpSettingManagementEntityFrameworkCoreModule),
    typeof(AbpEntityFrameworkCoreMySQLModule),
    typeof(AbpBackgroundJobsEntityFrameworkCoreModule),
    typeof(AbpAuditLoggingEntityFrameworkCoreModule),
    typeof(AbpTenantManagementEntityFrameworkCoreModule),
    typeof(AbpFeatureManagementEntityFrameworkCoreModule)
    )]
public class ConcreteMixDesignEntityFrameworkCoreModule : AbpModule
{
    /// <summary>
    /// 预配置服务(模块初始化)
    /// </summary>
    /// <param name="context"></param>
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        ConcreteMixDesignEfCoreEntityExtensionMappings.Configure();
    }
    /// <summary>
    /// 模块配置
    /// </summary>
    /// <param name="context"></param>
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        //注册数据上下文类
        context.Services.AddAbpDbContext<ConcreteMixDesignDbContext>(options =>
        {
                /* Remove "includeAllEntities: true" to create
                 * default repositories only for aggregate roots */
                //为聚合添加通用的仓储服务
            options.AddDefaultRepositories(includeAllEntities: true);
        });
        //配置数据上下文
        Configure<AbpDbContextOptions>(options =>
        {
                /* The main point to change your DBMS.
                 * See also ConcreteMixDesignMigrationsDbContextFactory for EF Core tooling. */
            options.UseMySQL();
        });

    }
}
